//This class read paraphrase patterns from the word file
package org.dbrd.paraphrase;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class ParaphraseReader {

	private final Map<String, String> patterns;


	public ParaphraseReader(String paraphraseFilePath) {
		this.patterns = new HashMap<String, String>();
		BufferedReader reader = null;
		try {
			reader = new BufferedReader(new FileReader(paraphraseFilePath));
			for (String line = reader.readLine(); line != null; line = reader.readLine()) {
				int pos0 = line.indexOf(" ");
				int pos = line.indexOf("| ");
				String firstWord = line.substring(pos0 + 1, pos).toLowerCase();
				int pos1 = line.indexOf("| ", pos + 1);
				String secondWord = line.substring(pos + 2, pos1).toLowerCase();
				// double weight = Double.parseDouble(line.substring(pos1 + 2));
				this.patterns.put(firstWord, secondWord);
				this.patterns.put(secondWord, firstWord);
			}
		} catch (IOException e) {
			throw new RuntimeException("Cannot read paraphrase pattern file " + paraphraseFilePath, e);
		} finally {
			if (reader != null) {
				try {
					reader.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}


	public Map<String, String> getPatterns() {
		return patterns;
	}
	
	
}
